/**
 * 
 */
package com.eshopper.product.controller;

import java.util.Date;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.eshopper.product.model.Product;
import com.eshopper.product.service.ProductService;

/**
 * @author Arun Kumar, Nov 19, 2014
 *
 */
@Controller
public class ProductController {
	
	private static final Logger logger = Logger.getLogger(ProductController.class);
	
	@Autowired
	ProductService productService;

	@RequestMapping(value = "/updateProduct", method = RequestMethod.GET)
	public ModelAndView updatePage() {
		return new ModelAndView("product-update-tiles");
	}

	@RequestMapping(value = "/updateProduct", method = RequestMethod.POST)
	public String updateProduct(@ModelAttribute("product")Product product, BindingResult result) {
		
		logger.info("ProductController : updateProduct method");
		
		product.setCreateDate(new Date());
		product.setCreatedBy(1l);
		product.setModifiedDate(new Date());
		product.setModifiedBy(1l);
		
		productService.addProduct(product);		
		logger.info(product);
		
		return "redirect:/updateProduct";
	}
}
